package com.ggshily.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

public class Util
{

	public static byte[] uncompress(byte[] data)
	{
		Inflater uncompressor = new Inflater();
		uncompressor.setInput(data);
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
		
		byte[] buff = new byte[1024];
		try
		{
			while(!uncompressor.finished())
			{
				int count = uncompressor.inflate(buff);
				bos.write(buff, 0, count);
			}
			
			bos.close();
		}
		catch(DataFormatException e)
		{
			
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return bos.toByteArray();
	}

}
